package cn.edu.zut.controller;

import cn.edu.zut.domain.AwardsInfo;
import cn.edu.zut.service.AwardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/awards")
public class AwardController {

    @Autowired
    private AwardService service;

    @RequestMapping("/findAll.do")
    public @ResponseBody List<AwardsInfo> findAll() {
        return service.findAll();
    }

    @RequestMapping("/add.do")
    public @ResponseBody void add(String STNumber,String relName,String className,String contestName,String awardLevel,String depName){
        int id=service.findEmptyId();//找一个获奖信息表中没有的_id
        AwardsInfo awardsInfo=new AwardsInfo(id, STNumber, relName, className, contestName, awardLevel, depName);
        service.add(awardsInfo);
    }

    @RequestMapping("/update.do")
    public @ResponseBody void update(int id, String STNumber,String relName,String className,String contestName,String awardLevel,String depName){
        AwardsInfo awardsInfo=new AwardsInfo(id, STNumber, relName, className, contestName, awardLevel, depName);
        service.update(awardsInfo);
    }

    @RequestMapping("/delete.do")
    public @ResponseBody void deleteByUserId(int id){ service.deleteByUserId(id); }

    @RequestMapping("/findByUserId.do")
    public @ResponseBody AwardsInfo findByUserId(int id){
        return service.findByUserId(id);
    }

    @RequestMapping("/findBySTNumberAndContestAndAward.do")
    public @ResponseBody AwardsInfo findBySTNumberAndContestAndAward(String STNumber, String contestName, String awardLevel){
        return service.findBySTNumberAndContestAndAward(STNumber,contestName,awardLevel);
    }

    @RequestMapping("/findLikeByPrint.do")
    public @ResponseBody List<AwardsInfo> findLikeByPrint(String STNumber, String contestName, String awardLevel){
        return service.findLikeByPrint(STNumber,contestName,awardLevel);
    }

    @RequestMapping("/findBySTNumber.do")
    public @ResponseBody List<AwardsInfo> findBySTNumber(String STNumber){
        return service.findBySTNumber(STNumber);
    }

    @RequestMapping("/findByContestName.do")
    public  @ResponseBody List<AwardsInfo> findByContestName(String contestName){
        return service.findByContestName(contestName);
    }

    @RequestMapping("/findAllByPrint.do")
    public @ResponseBody List<AwardsInfo> findAllByPrint(@RequestBody AwardsInfo awardsInfo) {
        System.out.println(awardsInfo);
        return service.findAllByPrint(awardsInfo);
    }

}
